using UnityEngine;
using System.Collections;

public class CursorMagic: MonoBehaviour {

	public float up = 3.0f;
	public string keyZCast="1";
	public float rotateSpeed = 30.0f;
	public Matrix4x4 rotateMatrix;

	private bool CastingZone = false;
	private Projector proj=null;
	
	void Start () {
		 proj = GetComponent("Projector") as Projector;
		 proj.enabled = false;
	}
 	void LateUpdate(){
		if(CastingZone){
			Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
		    RaycastHit hit;
			if (Physics.Raycast(ray, out hit, Mathf.Infinity))
			{
					Vector3 pos = hit.point;
					pos.y=up;
			        transform.position = pos;
			
			}
		}
		if(Input.GetKey("1") && !CastingZone)
		{
			CastingZone=true;
			proj.enabled = true;
			print ("Casting..");
		}
		if(Input.GetMouseButton(0) && CastingZone)
		{
			proj.enabled = false;
			CastingZone=false;
			print ("StopCasting");
		}
	}
	
	void LateUpdate_old(){
		if(CastingZone){
			Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
		    RaycastHit hit;
			if (Physics.Raycast(ray, out hit, Mathf.Infinity))
			{
					Vector3 pos = hit.point;
					pos.y=up;
			        transform.position = pos;
			}
		}
		if(Input.GetKey("1") && !CastingZone)
		{
			CastingZone=true;
			proj.enabled = true;
			print ("Casting..");
		}
		if(Input.GetMouseButton(0) && CastingZone)
		{
			proj.enabled = false;
			CastingZone=false;
			print ("StopCasting");
		}
		
			
	}
}
